home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: Another a.s.a.p. to do with structures and pointers and arrays
- Date: 16 Mar 1996 03:24:58 GMT
- Organization: Nando.net Public Access
- Message-ID: <4idcaa$741@castle.nando.net>
- References: <4ic8vq$fpn@badger.wmin.ac.uk>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: grail2615.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4ic8vq$fpn@badger.wmin.ac.uk>,
- Idoia Lertxundi <gsoec@wmin.ac.uk> writes:
-
- >I have a struct:
- >
- >typedef struct read_file_module_tag
- >{
- >char code[LENGTHCODE];
- >char module_name[LENGTHMODULE_NAME];
- >char description[LENGTHDESCRIPTION];
- >char module_leader[LENGTHLEADER];
- >char result[LENGTHRESULT];
- >char corecoursecodes[LENGTHCOURSECODES];
- >char optionalcoursecodes[LENGTHCOURSECODES];
- >char andprereqcodes[LENGTHREQUISITES];
- >char orprereqcodes[LENGTHREQUISITES];
- >char andcoreqcodes[LENGTHREQUISITES];
- >char orcoreqcodes[LENGTHREQUISITES];
- >struct read_file_module_tag *nextfm;
- >}FILEMODULE;
- >
- >look at the char courecoursecodes[XXX] O.K.?
- >
- >then reading a name1,name2,name3 list with strtok fuction
- >I have stored them in a
- >
- > char *ccoursecodes[10];
- >
- >then when I try do this copy:
- >
- > strcpy(mlst->corecoursecodes[i],ccoursecodes[i]);
- >the thing goes wrong no casting for argumenet 1.
-
- Well ya, the first argument is suppose to be a char *. Instead
- you are given strcpy a char. Copy a string into a char??? Also,
- you will need to define mist as a pointer to type FILEMODULE
- and, of course, allocate space for a structure of that type.
-
- >and if I change the above structure char type to char *...[]
- >does compile but it gives a segmentation fault when running.
- >Help!! S.O.S.
-
- Now you're getting warmer. The segmentation fault probably
- indicates that you failed to allocate memory for the string (re-
- member, you're only allocated space for an array of pointers,
- and not to what they point).
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-